#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys

"""
Documentation Author: Christopher Steel on behalf of Voice of Access
Copyright: Copyrighted (c) by Massimo Di Pierro (2007-2011)

runwen2py is used to run a set of files and the applications in
a corresponding "applications" folders using a virtualenv Web2py
packages and modules.

Using this command can be disconcerting for the uninitiated, new
to virtualenvs, pip, Web2py and so on. If this is you you may want
to stick to using the web2py_clone command for the time being as
it creates an environment that if much more familiar for most people.

Usage:

In order to use runweb2py you cd into the parent directory of
an applications directory that was (probably) created using the 
mkweb2pyenv command.

So if you ran

mkweb2pyenv /home/my_user/venvs/texas123

then you would do:

cd /home/my_user/venvs/texas123

and then run

runweb2py

and your virtualenvs Web2py related "executables", in other
words:

lib/python.x.x/site-packages/*
and
lib/python.x.x/site-packages/gluon/*

Will be used to run the application you have located in the

/home/my_user/venvs/texas123/applications

directory.

See, I told ya to stick to the web2py_clone command for now and
ya didn't believe me!

"""


path = os.getcwd()
try:
    if sys.argv[1] and os.path.exists(sys.argv[1]):
        path = sys.argv[1]
except:
    pass

os.chdir(path)
sys.path = [path]+[p for p in sys.path if not p==path]
# import gluon.import_all ##### This should be uncommented for py2exe.py
import gluon.widget

def main():
    # Start Web2py and Web2py cron service!
    gluon.widget.start(cron=True)

if __name__ == '__main__':
    main()
